﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Weixin.Utils;

namespace ChinaTaxService
{
    public partial class userindex : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string appid = WebConfig.GetAppSetting("AppId");
            string secret = WebConfig.GetAppSetting("AppSecret");
            if (string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                string redirect_uri = Server.UrlEncode("http://wx.china-tax.org/fw/userindex.aspx");
                string scope = "snsapi_base";
                string state = "tony";
                linkOpen.HRef = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + redirect_uri + "&response_type=code&scope=" + scope + "&state=" + state + "#wechat_redirect";
            }
            else
            {
                string code = Request.QueryString["code"];
                string res = WebRequestHelper.GetData("https://api.weixin.qq.com/sns/oauth2/access_token", "appid=" + appid + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code");
                lBase.Text = res;
            }
        }
    }
}